package com.abei.gas.controller;

import cn.hutool.core.util.StrUtil;
import com.abei.gas.entity.Card;
import com.abei.gas.entity.Device;
import com.abei.gas.service.DeviceService;
import com.abei.gas.vo.DataVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/device")
@Api(tags = "设备管理相关接口")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    @PostMapping("/insert")
    public DataVo insert(@RequestBody Device device){
        deviceService.save(device);
        return DataVo.success();
    }

    @RequestMapping("/deleteById")
    public void deleteById(HttpServletRequest request){
        String id = request.getParameter("id");
        deviceService.deleteById(id);
    }

    @PostMapping("/update")
    public DataVo update (@RequestBody Device device){
        deviceService.updateById(device);
        return DataVo.success();
    }

    @GetMapping("/findAll")
    public DataVo<Device> findAll(Integer page,Integer limit){
        return deviceService.findAll(page,limit);
    }

    @GetMapping("/selectById")
    public DataVo<Device> selectById(HttpServletRequest request) {
        String id = request.getParameter("id");
        return deviceService.findById(id);
    }
    /*
     * 批量删除
     * */
    @RequestMapping("/deleteBatchIds")
    public void DDeletebatchIds(HttpServletRequest request){
        String ids=request.getParameter("ids");
        deviceService.DeleteBatchIds(ids);
    }
}
